package LeetCode.leetcode;

/**
 * @author leiwenkang
 * @date 2020/6/17
 */
public class Test744寻找比目标字母大的最小字母 {
    public static void main(String[] args) {
        char[] letters = {'c', 'f', 'j'};
        System.out.println(nextGreatestLetter(letters, 'd'));

    }

    public static char nextGreatestLetter(char[] letters, char target) {
        int low = 0;
        int height = letters.length - 1;
        if (target < letters[0] || target >= letters[height]) {
            return letters[0];
        }
        while (low <= height) {
            int mid = low + (height - low) / 2;
            if (letters[mid] <= target) {
                low = mid + 1;
            } else {
                height = mid - 1;
            }
        }
        return letters[low];
    }
}
